<?php
/**
 * Created by PhpStorm.
 * User: MrHung
 * Date: 5/13/14
 * Time: 10:09 AM
 */

namespace Frontend\Controller;


use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\ArrayObject;
use Zend\View\Model\ViewModel;
use Velacolib\Utility\Utility;
use Frontend\Helper\MobileDetect;

class PageController extends AbstractActionController {

    protected $pageTable;
    protected $translator;
    protected $isPhone;
    protected $isTablet;


    /**
     * @param \Zend\Mvc\MvcEvent $e
     * @return mixed
     */
    public function onDispatch(\Zend\Mvc\MvcEvent $e)
    {
        //Utility::CheckLogin($this,'/user/login');

        $this->pageTable = Utility::UserGateway('Admin\Model\AdminPageTable');
        $this->translator = Utility::translate();


        $this->layout('frontend/layout');

        return parent::onDispatch($e);
    }

    public function indexAction(){

    }

    /**
     * @return ViewModel
     */
    public function baivietAction(){
        $slug = $this->params()->fromRoute('slug');
        $baivietData = $this->pageTable->getPageByslug($slug);

            if($baivietData == null){
                $this->getResponse()->setStatusCode(404);
                $viewModel = new ViewModel();
                $viewModel->setTerminal(true);
                return $viewModel;
            }

        return new ViewModel(array(
            'page'=>$baivietData,
        ));
    }





} 